<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>后台登录-blog</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" th:href="@{/X-admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/X-admin/css/login.css}">
    <link rel="stylesheet" th:href="@{/X-admin/css/xadmin.css}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" th:src="@{/X-admin/lib/layui/layui.js}" charset="utf-8"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body onkeydown="enterSubmit(event)" class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">blog-管理登录</div>
    <div id="darkbannerwrap"></div>

    <div class="layui-form">
        <span class="x-red" th:if="${session.errorMsg != null}" th:text="${session.errorMsg}"></span>
        <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div id="slider"></div>
        <hr class="hr15">
        <input id="login" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </div>
</div>
<script>

    function enterSubmit(obj) {
        //当enter 键按下后，需要执行的事件
        var button = document.getElementById('login');
        if (obj.keyCode == 13) {
            button.click();
        }
    }

    layui.config({
        base: '/X-admin/js/'
    }).use(['sliderVerify', 'form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            sliderVerify = layui.sliderVerify,
            $ = layui.jquery;

        var slider = sliderVerify.render({
            elem: '#slider',
            // 当验证通过回调
            onOk: function () {
                layer.msg("滑块验证通过");
            }
        });

        // 监听提交
        form.on('submit(login)', function (data) {
            // 用于表单验证是否已经滑动成功
            if(slider.isOk()){
                $.ajax({
                    url: "/admin/v1/login",
                    type: "post",
                    data: data.field,
                    success: function(s) {
                        if (s.resultCode == 200) {
                            //加载层-风格3
                            layer.load(2);
                            setTimeout(function () {
                                layer.closeAll('loading');
                            }, 1500);
                            layer.msg(s.message, function () {
                                location.href = s.data;
                            });
                        } else {
                            layer.msg(s.message, function () {
                            });
                        }
                    },
                    error:function(){
                        layer.msg("接口异常!", function () {});
                    }
                });
            }else{
                layer.msg("请先通过滑块验证");
            }
        });
    });
</script>
<!-- 底部结束 -->
</body>
</html>